<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>影厅列表</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css" media="all">
    <script src="${pageContext.request.contextPath}/layui/layui.js" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <style>
        .shadows{
            background-color: #b2b2b2;

        }
    </style>
</head>

<body>
<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="add()">
    <i class="layui-icon">&#xe61f;</i>增加
</button>

<!-- 弹出层中的表单模板 -->
<form id="roleEditForm" class="layui-form" action="roomInsert" method="post" style="display:none;padding-top:10px;">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">ID</label>
            <div class="layui-input-inline">
                <input type="text" name="id" class="layui-input" id="id" placeholder="ID" required
                       lay-verify="required">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-inline">
            <input type="text" name="name" id="lantype" required lay-verify="required" placeholder="请输入"
                   autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">座位</label>
            <div class="layui-input-inline" style="width: 100px;">
                <input type="text" name="row" placeholder="行" required lay-verify="required" autocomplete="off"
                       onkeyup="this.value=this.value.replace(/\D/g,'')" class="layui-input">
            </div>
            <div class="layui-form-mid">-</div>
            <div class="layui-input-inline" style="width: 100px;">
                <input type="text" name="column" placeholder="列" required lay-verify="required" autocomplete="off"
                       onkeyup="this.value=this.value.replace(/\D/g,'')" class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="button" class="layui-btn layui-btn-primary" onclick="closeEditWin()">取消</button>
        </div>
    </div>

</form>

<table class="layui-hide" id="test"></table>

<script>

    layui.use(['table','layer'], function () {
        var table = layui.table;
        var layer = layui.layer;
        var $ = layui.$;

        table.render({
            elem: '#test',
            url: 'roomAll',
            // cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            //     ,
            cols: [
                [{
                    field: 'roomId',
                    align: 'center',
                    title: 'ID',
                    sort: true
                }, {
                    field: 'roomName',
                    align: 'center',
                    title: '影厅名'
                }, {
                    field: 'situation',
                    align: 'center',
                    title: '座位'
                }, {
                    field: 'setUp',
                    align: 'center',
                    title: '设置'
                }]
            ],
            page:{layout:['limit', 'count', 'prev', 'page', 'next', 'skip']},
            limit:5,
            limits:[1,2,3,4,5]

        });
        $("table").on("click", "button", function(e){
            // 这里的this指向触发点击事件的p元素(Element)
            // var btn = e.currentTarget ;
            // console.log(e.target.id)
            // console.log($(this).text())
            // console.log(btn)
            $.ajax({
                type: "get",
                url: "show/"+e.target.id,
                dataType: "json",
                success: function (data) {
                    // console.log(data);
                    doBack(data[0]);
                }
            });

            function doBack(responseText) {
                layer.open({
                    type: 1,
                    area: [300, 300],
                    skin: 'shadows',
                    title: '座位分布',
                    content: responseText,
                });
            }
        });
    });

    function add() {
        var obj = {
            "action": "roomInsert",
            "tit": "增加影厅"
        }
        popupwin(obj);
    }

    function popupwin(obj) {
        layui.use(['layer'], function () {
            var layer = layui.layer;
            var $ = layui.jquery;
            $('#roleEditForm').attr('action', obj.action);
            layer.open({
                type: 1, //5种层类型。可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
                area: [500], //宽高
                title: obj.tit,
                content: $('#roleEditForm')
            });
        });
    }

    function closeEditWin() {
        layui.use('layer', function () {
            var layer = layui.layer;
            layer.closeAll();
        });
    }

</script>


</body>

</html>